package com.yangming.springboot.deepin.playTest;

import com.yangming.springboot.deepin.playTest.SleepUtils;

/**
 * @创建人 ym
 * @创建时间 2021/4/7 0007
 * @描述
 **/
public class ThreadState {

    public static void main(String[] args){
        new Thread(new TimeWaiting(), "TimeWaiting").start();
        new Thread(new Waiting(), "waiting").start();
        new Thread(new Blocked(), "blockThread-1").start();
        new Thread(new Blocked(), "blockThread-2").start();
    }

    public static class TimeWaiting implements Runnable{

        @Override
        public void run(){
            while(true){
                SleepUtils.second(100);
            }
        }
    }

    public static class Waiting implements Runnable{
        @Override
        public void run(){
            while(true){
                synchronized(Waiting.class){
                    try{
                        Waiting.class.wait();
                    }catch(InterruptedException e){
                        e.printStackTrace();
                    }
                }
            }
        }
    }

    public static class Blocked implements Runnable{
        @Override
        public void run(){
            synchronized(Blocked.class){
                while(true){
                    SleepUtils.second(100);
                }
            }
        }
    }

}
